package com.mock.action.organisation.team;

import java.util.List;

import com.mock.action.AbstractAction;
import com.mock.dao.BusinessTypeDao;
import com.mock.dao.ContactDao;
import com.mock.dao.CountryDao;
import com.mock.dao.DepartmentDao;
import com.mock.dao.TeamDao;
import com.mock.dao.impl.BusinessTypeDaoImpl;
import com.mock.dao.impl.ContactDaoImpl;
import com.mock.dao.impl.CountryDaoImpl;
import com.mock.dao.impl.DepartmentImpl;
import com.mock.dao.impl.TeamDaoImpl;
import com.mock.model.BusinessType;
import com.mock.model.Contact;
import com.mock.model.Country;
import com.mock.model.Department;
import com.mock.model.Team;

public class AddTeamAction extends AbstractAction {

	/**
	 * 
	 */
	/* Business Method */
	private static final long serialVersionUID = 1798349491090852199L;
	
	public String execute() {
		setCountries(new CountryDaoImpl().getAllCountry());
		return SUCCESS;
	}
	
	public String addTeam() {
		TeamDao teamDao = new TeamDaoImpl();
		CountryDao countryDao = new CountryDaoImpl();
		ContactDao contactDao = new ContactDaoImpl();
		DepartmentDao departmentDao = new DepartmentImpl();
		BusinessTypeDao businessTypeDao = new BusinessTypeDaoImpl();
		Country country = null;
		Contact contact = null;
		BusinessType businessType = null;
		if (countryId == -1) {
			country = null;
		} else {
			country = countryDao.getById(countryId);
		}
		
		if (contactIden != null) {
			contact = contactDao.getById(Contact.class, contactIden);
		}
		
		if (businessId != null) {
			businessType = businessTypeDao.getById(businessId);
		}
		
		Department department = departmentDao.getById(Department.class, departmentId);
		Team team = new Team(name, shortDescription, fullDescription, contact, 
				addressLine1, addressLine2, addressLine3, 
				postcode, town, county, country, 
				businessType, phonenumber, fax, email, webAddress, false, department);
		teamDao.add(team);
		return SUCCESS;
	}
	
	
	/* Getter & Setter */
	private String name;
	private String shortDescription;
	private String fullDescription;
	private String addressLine1;
	private String addressLine2;
	private String addressLine3;
	private String postcode;
	private String town;
	private String county;
	private Long countryId;
	private String phonenumber;
	private String fax;
	private String email;
	private String webAddress;
	private boolean active;
	private Long contactIden;
	private List<Country> countries;
	private Long businessId;
	private Long departmentId;

	public Long getDepartmentId() {
		return departmentId;
	}

	public void setDepartmentId(Long departmentId) {
		this.departmentId = departmentId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getShortDescription() {
		return shortDescription;
	}

	public void setShortDescription(String shortDescription) {
		this.shortDescription = shortDescription;
	}

	public String getFullDescription() {
		return fullDescription;
	}

	public void setFullDescription(String fullDescription) {
		this.fullDescription = fullDescription;
	}

	public String getAddressLine1() {
		return addressLine1;
	}

	public void setAddressLine1(String addressLine1) {
		this.addressLine1 = addressLine1;
	}

	public String getAddressLine2() {
		return addressLine2;
	}

	public void setAddressLine2(String addressLine2) {
		this.addressLine2 = addressLine2;
	}

	public String getAddressLine3() {
		return addressLine3;
	}

	public void setAddressLine3(String addressLine3) {
		this.addressLine3 = addressLine3;
	}

	public String getPostcode() {
		return postcode;
	}

	public Long getBusinessId() {
		return businessId;
	}

	public void setBusinessId(Long businessId) {
		this.businessId = businessId;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	public String getTown() {
		return town;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String getCounty() {
		return county;
	}

	public void setCounty(String county) {
		this.county = county;
	}

	public Long getCountryId() {
		return countryId;
	}

	public void setCountryId(Long countryId) {
		this.countryId = countryId;
	}

	public String getPhonenumber() {
		return phonenumber;
	}

	public void setPhonenumber(String phonenumber) {
		this.phonenumber = phonenumber;
	}

	public String getFax() {
		return fax;
	}

	public void setFax(String fax) {
		this.fax = fax;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getWebAddress() {
		return webAddress;
	}

	public void setWebAddress(String webAddress) {
		this.webAddress = webAddress;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public List<Country> getCountries() {
		return countries;
	}

	public void setCountries(List<Country> countries) {
		this.countries = countries;
	}

	public Long getContactIden() {
		return contactIden;
	}

	public void setContactIden(Long contactIden) {
		this.contactIden = contactIden;
	}
}
